import { StyleProp, TextStyle } from 'react-native'
import pinkStyle from './pink'
import redStyle from './red'

export const styleThemes: Record<string, any> = Object.freeze({
    pink: pinkStyle,
    red: redStyle,
})

interface mergeStyleProps {
    theme: string
    style?: StyleProp<TextStyle>
    themeStyle?: Record<string, any>
}

export const mergeStyles = ({ style, themeStyle, theme }: mergeStyleProps): StyleProp<TextStyle> => {
    const stl: Record<string, any> = style && typeof style === 'object' ? { ...style } : {}
    if (themeStyle && typeof themeStyle === 'object') {
        Object.keys(themeStyle).forEach((key) => {
            stl[key] = styleThemes[theme][themeStyle[key]]
        })
    }
    return stl
}

/**
 * 获取单个颜色值
 * @param theme 当前肤色
 * @param key 颜色定义的key
 * @returns {string} 颜色值
 */
export const getColorStr = (theme: string, key: string) => {
    if (theme && key) {
        return styleThemes[theme][key]
    }
    return ''
}